package tt.dz.egobus.servicemanager.vo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import tt.dz.egobus.servicemanager.bean.EntityViewVo;
import tt.dz.egobus.servicemanager.entities.Bus;
import tt.dz.egobus.servicemanager.entities.BusRegisterService;
import tt.dz.egobus.servicemanager.entities.BusService;

import javax.validation.constraints.NotNull;

/**
 * @author Anson
 * @date 17-4-14
 * @name
 * @since 1.0.4
 */
public class BusRegisterServiceViewVo implements EntityViewVo<BusRegisterService, BusRegisterServiceViewVo> {
    private static final long serialVersionUID = 3696463293704207235L;
    private static final Logger LOGGER = LoggerFactory.getLogger(BusRegisterServiceViewVo.class);


    @Override
    public BusRegisterService convert() {
        BusRegisterService pojo = new BusRegisterService();
        try {
            BeanUtils.copyProperties(this, pojo);
        } catch (BeansException e) {
            LOGGER.error("BusRegisterServiceVo -> BusRegisterService bean拷贝异常, viewVo={}", this, e);
        }
        return pojo;
    }

    @Override
    public BusRegisterServiceViewVo view(BusRegisterService pojo) {
        if (pojo == null) {
            return this;
        }
        this.setId(pojo.getId());
        this.setBusId(pojo.getBusId());
        this.setBusServiceId(pojo.getBusServiceId());
        this.setIsValidate(pojo.getIsValidate());
        Bus bus = pojo.getBus();
        if (bus != null) {
            this.setBusViewVo(new BusViewVo().view(bus));
        }
        BusService busService = pojo.getBusService();
        if (busService != null) {
            this.setServiceViewVo(new BusServiceViewVo().view(busService));
        }
        return this;
    }

    private String id;


    /**
     * 车辆id
     */
    @NotNull(message = "车辆不能为空")
    private String busId;


    /**
     * 车辆服务类型Id
     */
    @NotNull(message = "车辆服务类型不能为空")
    private String busServiceId;

    /**
     * 是否有效
     */
    private boolean isValidate = false;


    /**
     * view 车辆信息
     */
    private BusViewVo busViewVo;

    /**
     * view 服务
     */
    private BusServiceViewVo serviceViewVo;

    public String getBusId() {
        return busId;
    }

    public void setBusId(String busId) {
        this.busId = busId;
    }

    public String getBusServiceId() {
        return busServiceId;
    }

    public void setBusServiceId(String busServiceId) {
        this.busServiceId = busServiceId;
    }

    public boolean getIsValidate() {
        return isValidate;
    }

    public void setIsValidate(boolean validate) {
        isValidate = validate;
    }

    public BusViewVo getBusViewVo() {
        return busViewVo;
    }

    public void setBusViewVo(BusViewVo busViewVo) {
        this.busViewVo = busViewVo;
    }

    public BusServiceViewVo getServiceViewVo() {
        return serviceViewVo;
    }

    public void setServiceViewVo(BusServiceViewVo serviceViewVo) {
        this.serviceViewVo = serviceViewVo;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof BusRegisterServiceViewVo)) return false;

        BusRegisterServiceViewVo that = (BusRegisterServiceViewVo) o;

        if (getIsValidate() != that.getIsValidate()) return false;
        if (getId() != null ? !getId().equals(that.getId()) : that.getId() != null) return false;
        if (getBusId() != null ? !getBusId().equals(that.getBusId()) : that.getBusId() != null) return false;
        return getBusServiceId() != null ? getBusServiceId().equals(that.getBusServiceId()) : that.getBusServiceId() == null;

    }

    @Override
    public int hashCode() {
        int result = getId() != null ? getId().hashCode() : 0;
        result = 31 * result + (getBusId() != null ? getBusId().hashCode() : 0);
        result = 31 * result + (getBusServiceId() != null ? getBusServiceId().hashCode() : 0);
        result = 31 * result + (getIsValidate() ? 1 : 0);
        return result;
    }

    @Override
    public String toString() {
        return "BusRegisterServiceViewVo{" +
                "id='" + id + '\'' +
                ", busId='" + busId + '\'' +
                ", busServiceId='" + busServiceId + '\'' +
                ", isValidate=" + isValidate +
                '}';
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}
